#include "gameManager.h"
#include "constant.h"
#include "Boss.h"
#include "stdBossLib.h"

void gameManager::draw()
{
	if (!*stop)
	{
		//draw gameStop and effect
	}
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
	_backManager.draw();
	_burstManager->draw();
	_bulletManager->draw();
	_itemManager->draw();
	_selfBulletManager->draw();
	_selfBoneManager->draw();
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE);
	_effectManager->draw();
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
	_bossManager->draw();
	_emenyManager->draw();
	p.draw();
}

void gameManager::updata()
{
	if (!*stop)
	{
		if (!BOSSSTATUS)
		{
			//cout << BOSSSTATUS << endl;
			message* m;
			m = _dramaFactory.getMessage();
			while (m)
			{
				if (m->flag == CREATEENEMY)
				{
					_emenyManager->add(_stdEmenyLib->getEmeny(m->emenyKind),
						m->p, p.getPoint());
				}else if (m->flag == CHANGEBACKGROUND)
				{
					_backManager.setGlobalMessage(m);
				}else if (m->flag == SETLOGO)
				{
					_backManager.setGlobalMessage(m);
				}else if (m->flag == CREATEBOSS)
				{
					stdBossLib* lib = 0;
					lib = lib->Instance();
					Boss* b = new Boss(lib->getBoss(0),
						Point(100, 100), p.getPoint());
					BOSSSTATUS = true;
					_bossManager->add(b);
				}
				m = _dramaFactory.getMessage();
			}
			_dramaFactory.updata();
		}		
		p.updata();
		_bossManager->updata();
		_boneManager->updata();
		_selfBoneManager->updata();
		_backManager.updata();
		_burstManager->updata();
		_emenyManager->updata();
		_itemManager->updata();
		
		_selfBulletManager->updata();
		_bulletManager->updata();	
		_effectManager->updata();
		checkHit();
	}
}

void gameManager::checkHit()
{
	_bulletManager->checkHit(p);
	_emenyManager->checkHitPlayer(p);
	_itemManager->checkHit(p);
	_bossManager->checkHitBullet();
	_emenyManager->checkHitBullet();
}